package com.imooc.controller;

import com.imooc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018\5\17 0017.
 */
@Controller
@RequestMapping("th")
public class ThymeleafController {

    @RequestMapping("/index")
    public String index(ModelMap map) {
        map.addAttribute("name", "thymeleaf-imooc");
        return  "thymeleaf/index";
    }

    @RequestMapping("/center")
    public String index() {
        return  "thymeleaf/center/center";
    }

    @RequestMapping("/test")
    public String test(ModelMap map) {
        User user = new User();
        user.setName("superadmin");
        user.setAge(18);
        user.setBirthday(new Date());
        user.setDesc("<font color='green'><b>hello<b/></font>");
        map.addAttribute("user", user);

        User user1 = new User();
        user1.setName("Licy");
        user1.setAge(20);
        user1.setBirthday(new Date());

        List<User> userList = new ArrayList<>();
        userList.add(user);
        userList.add(user1);
        map.addAttribute("userList", userList);
        return  "thymeleaf/test";
    }

    @PostMapping("/postform")
    public String postform(User user) {
        System.out.println(user.getName());
        return  "redirect:/th/test";
    }
}
